﻿using System;
using System.Web.UI;
using CurriculumData;

namespace CurriculumSite
{
    public partial class LoginWebUserControl : UserControl
    {
        #region Members

        private readonly Controller _controller = new Controller();

        #endregion

        #region Events

        public event EventHandler LoggedIn;

        #endregion

        #region Event Handlers

        protected void enterASPxButton_Click(object sender, EventArgs e)
        {
            int? candidateId = _controller.Login(taxNumberASPxTextBox.Text, passwordASPxTextBox.Text);
            if (candidateId == null)
                return;
            Session["CandidateId"] = candidateId;
            OnLoggedIn();
        }

        #endregion

        #region Private Methods

        private void OnLoggedIn()
        {
            EventHandler loggedIn = LoggedIn;
            if (loggedIn != null)
                loggedIn(this, new EventArgs());
        }

        #endregion
    }
}